package com.nihao.vido;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
 * Created by 赵航帅哥 on 2017/2/16.
 */

public class SendAndReciver {

    public static DatagramSocket mDatagramSocket=null;
    public static void sendMsg(final String stop, final String masg, final String trim, final int nunber) {

        //开启子线程
        new Thread(){
            @Override
            public void run() {
                try {
                    //1.指定端口号
                    mDatagramSocket = new DatagramSocket(0);

                    while (true) {
                        if (stop.equals("stop")) {
                            break;
                        }
                        //2,指定发送信息的长度,主机名字
                        //3连续发送用
                        DatagramPacket datagramPacket = new DatagramPacket(masg.getBytes(), masg.getBytes().length, InetAddress.getByName(trim), nunber);
                        mDatagramSocket.send(datagramPacket);
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }finally {
                    if (mDatagramSocket!=null){
                        mDatagramSocket.close();
                    }
                }

            }
        }.start();

    }
    public static void ResaveMsg(){

    }
}
